/*!
//      
//      \file	k2k_Signal.h
//      
//      \author	Copyright 2010 Valentina Vuksic <vuksv1@bfh.ch>, Beat Liechti <liecb2@bfh.ch>
//      
//      This program is free software; you can redistribute it and/or modify
//      it under the terms of the GNU General Public License as published by
//      the Free Software Foundation; either version 2 of the License, or
//      (at your option) any later version.
//      
//      This program is distributed in the hope that it will be useful,
//      but WITHOUT ANY WARRANTY; without even the implied warranty of
//      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//      GNU General Public License for more details.
//      
//      You should have received a copy of the GNU General Public License
//      along with this program; if not, write to the Free Software
//      Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
//      MA 02110-1301, USA.
//
//		Abstract Data Type for signal handling
//      
//      \brief		CAS-EBX-03 Projektarbeit 
//      			Valentina Vuksic (VUKSV1), Beat Liechti (LIECB2)
//      			Signal ADT for the k2k (Kaffee2000) application
//      \version	1.0
//      \date		2010-04-11
//      \remark		Last Modifications:
//      \remark  	v1.0, VUKSV1/LIECB2, 2010-05-05 Initial release
//
*/

#ifndef __k2k_Signal__
#define __k2k_Signal__

#include <stdlib.h>
#include <unistd.h>
#include <signal.h>

typedef void (*k2k_Signal_CallbackFunc)(int sigNo, void *customData);

/*!
// k2k_Signal defines the data structure for the ADT 
// \brief k2k_Signal stuct for ADT
*/				
typedef struct k2k_Signal_Struct
{	
	/*! callback function to signal receiver */
    k2k_Signal_CallbackFunc callback;
    /*! data for callback function */
    void *customData;
	/*! process id of signal receiver */
	pid_t pid;
	/*! signal type: SIGHUP, SIGINT, SIGUSR1, SIGUSR2, etc */
	int sigNo;	
	/*! previous signal handler */ 
	struct sigaction oldAction;
	/*! new signal handler */
	struct sigaction usrAction;	
    /*! block mask for signaling */
    sigset_t blockMask;
    /*! flag to track enable/disable status */
    volatile int enabled;
} k2k_Signal;

/*!
//
// Creates Signal ADT "object"
//
// \param sigNo si the signal type: SIGHUP, SIGINT, SIGUSR1, SIGUSR2, etc
// \param callback is the callback function (signal receiver)
// \param customData is a pointer to custom data to call the callback function with
// 
// \return pointer to the Signal ADT
//
*/
k2k_Signal* k2k_Signal_Create(int sigNo, k2k_Signal_CallbackFunc callback, void *customData);

/*!
//
// Releases Signal ADT "object"
// 
// \param signal is the pointer to the Signal structure
// 
// \return noting
//
*/
void k2k_Signal_Release(k2k_Signal *signal);

/*!
//
// Enables signal handling
// 
// \param signal is the pointer to the Signal structure 
// 
// \return noting
//
*/
void k2k_Signal_Enable(k2k_Signal *signal);

/*!
//
// Disables signal handling
// 
// \param signal is the pointer to the Signal structure 
// 
// \return noting
//
*/
void k2k_Signal_Disable(k2k_Signal *signal);

/*!
//
// Raises a signal (to be called by forked process)
// 
// \param signal is the pointer to the Signal structure 
// 
// \return noting
//
*/
void k2k_Signal_Raise(k2k_Signal *signal);

#endif
